﻿using AutoMapper;
using Enferno.Public.Web.Models;
using Enferno.StormApiClient.Customers;

namespace Enferno.Public.Web.Mappers.CheckoutProfiles
{
    public class CompanyToCompanyModelProfile :
        CompanyToCompanyBaseModelProfile<CompanyModel, CompanyInformationModel, AddressModel>
    {
        
    }

    public class CompanyToCompanyBaseModelProfile<TCompanyModel, TCompanyInformationModel, TAddressModel> : Profile
        where TCompanyModel: CompanyBaseModel<TCompanyInformationModel, TAddressModel>
        where TCompanyInformationModel: CompanyInformationModel
        where TAddressModel: AddressModel
    {
        protected override void Configure()
        {

            Mapper.CreateMap<Company, TCompanyInformationModel>();
            Mapper.CreateMap<TCompanyInformationModel, Company>()
                .ForMember(to => to.Id, opts => opts.Ignore())
                .ForMember(to => to.Key, opts => opts.Ignore())
                .ForMember(to => to.Code, opts => opts.Ignore())
                .ForMember(to => to.OrgNo, opts => opts.Ignore())
                .ForMember(to => to.ReferId, opts => opts.Ignore())
                .ForMember(to => to.ReferUrl, opts => opts.Ignore())
                .ForMember(to => to.DeliveryAddresses, opts => opts.Ignore())
                .ForMember(to => to.InvoiceAddress, opts => opts.Ignore())
                .ForMember(to => to.ParentId, opts => opts.Ignore())
                .ForMember(to => to.DeliveryMethodIds, opts => opts.Ignore())
                .ForMember(to => to.PaymentMethodIds, opts => opts.Ignore())
                .ForMember(to => to.UseInvoiceAddressAsDeliveryAddress, opts => opts.Ignore())
                .ForMember(to => to.Info, opts => opts.Ignore())
                .ForMember(to => to.PricelistIds, opts => opts.Ignore())
                .ForMember(to => to.ExtensionData, opts => opts.Ignore());

            Mapper.CreateMap<Company, TCompanyModel>()
                .ForMember(to => to.CompanyInformation,
                    opts => opts.MapFrom(from => Mapper.Map<Company, TCompanyInformationModel>(from)));
        }
    }
}
